<template>
  <div class = "container1">
    <div class="input-group mb-3">
      <input type="text" class="form-control" placeholder="输入客户名" aria-label="Recipient's username"
             aria-describedby="button-addon2" v-model="this.customerName">

      <button class="btn btn-outline-secondary" type="button" id="button-addon2" @click="getByName">客户名查询</button>
      <button type="button" class="btn btn-outline-primary" @click="getZeroList">未审核</button>
      <button type="button" class="btn btn-outline-primary" @click="getOneList">已同意</button>
      <button type="button" class="btn btn-outline-primary" @click="getTwoList">已驳回</button>
    </div>
  </div>
  <div v-for="(item, index) in allList" :key="item.redoApplication.applicationNumber">
    <div class="container2">
      <table class="table">
        <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">客户名</th>
          <th scope="col">外部等级</th>
          <th scope="col">严重性</th>
          <th scope="col">申请时间</th>
          <th scope="col">审核状态</th>
          <th scope="col">审核时间</th>
          <th scope="col">审核人</th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <th scope="row">{{++index}}</th>
          <td>{{item.customer.customerName}}</td>
          <td>{{item.customer.rank}}</td>
          <td>{{item.redoApplication.severity}}</td>
          <td>{{item.redoApplication.applicationTime}}</td>
          <td>{{item.redoApplication.approvementStatus==0 ? "未审核":(item.redoApplication.approvementStatus==1?'已同意':'已驳回') }}</td>
          <td>{{item.redoApplication.approvementTime}}</td>
          <td>{{item.redoApplication.redoApproverName}}</td>
        </tr>
        </tbody>
      </table>
      <div style="width: 650px;display: inline-block">
        <h6>重生</h6>
        <div>
          {{item.redoReason}}
        </div>
      </div>
      <div style="width: 650px;display: inline-block">
        <div class="d-grid gap-2">
          <button class="btn btn-primary btn-success" type="button" @click="agree(item)">同意</button>
          <button class="btn btn-primary btn-danger" type="button" @click="disagree(item)">拒绝</button>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  name: 'ApproverRedoApplication',
  data(){
    return {
      allList:[],
      customerName:"",

    }
  },

  methods: {

    async getAllList(){
      const {data: res} = await this.$http.get('/redoApplication/allList')
      this.allList=res.data
    },
    async getZeroList(){
      const {data: res}= await this.$http.get('/redoApplication/searchByStatusZero')
      this.allList=res.data
    },
    async getOneList(){
      const {data: res}= await this.$http.get('/redoApplication/searchByStatusOne')
      this.allList=res.data
    },
    async getTwoList(){
      const {data: res}= await this.$http.get('/redoApplication/searchByStatusTwo')
      this.allList=res.data
    },
    async getByName(){
      const {data: res}= await this.$http.get('/redoApplication/searchByName?customerName='+this.customerName)
      this.allList=res.data
    },

    async agree(item){
      const {data:res}=await this.$http.get('/redoApplication/agree?applicationNumber='+item.redoApplication.applicationNumber
          +'&approverAccount='+localStorage.getItem('approverAccount'))
      if (res.data===0){
        alert('操作成功')
      }else {
        alert('操作失败')
      }
      await this.getAllList()
    },

    async disagree(item){
      const {data:res}=await this.$http.get('/redoApplication/disagree?applicationNumber='+item.redoApplication.applicationNumber
          +'&approverAccount='+localStorage.getItem('approverAccount'))
      if (res.data===0){
        alert('操作成功')
      }else {
        alert('操作失败')
      }

      await this.getAllList()
    }



  },




  created() {
    this.getAllList()
  }

}


</script>

<style lang="less" scoped>
.container1 {
  margin: 20px auto;
  max-width: 700px;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}


.container2 {
  margin: 20px auto;
  max-width: 1400px;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
</style>